import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../models/family_member.dart';

/// 家庭成员列表项组件
class MemberListItem extends StatelessWidget {
  /// 成员数据
  final FamilyMember member;
  /// 点击回调
  final VoidCallback? onTap;
  /// 编辑回调
  final VoidCallback? onEdit;

  /// 构造函数
  const MemberListItem({
    Key? key,
    required this.member,
    this.onTap,
    this.onEdit,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(bottom: 8.h),
      child: InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(8.r),
        child: Padding(
          padding: EdgeInsets.all(12.w),
          child: Row(
            children: [
              // 头像
              CircleAvatar(
                radius: 24.r,
                backgroundImage: member.avatarUrl != null
                    ? NetworkImage(member.avatarUrl!)
                    : null,
                child: member.avatarUrl == null
                    ? Icon(Icons.person, size: 24.r)
                    : null,
              ),
              SizedBox(width: 16.w),
              // 成员信息
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Text(
                          member.name,
                          style: const TextStyle(fontWeight: FontWeight.bold),
                        ),
                        if (member.isCurrentUser) ...[  
                          SizedBox(width: 4.w),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.h),
                            decoration: BoxDecoration(
                              color: Colors.blue.withOpacity(0.1),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: const Text(
                              '我',
                              style: TextStyle(fontSize: 10, color: Colors.blue),
                            ),
                          ),
                        ],
                      ],
                    ),
                    SizedBox(height: 4.h),
                    Row(
                      children: [
                        Icon(member.role.icon, size: 14.sp, color: Colors.grey),
                        SizedBox(width: 4.w),
                        Text(
                          member.role.displayName,
                          style: TextStyle(fontSize: 12.sp, color: Colors.grey),
                        ),
                        if (member.age != null) ...[  
                          SizedBox(width: 8.w),
                          Text(
                            '${member.age}岁',
                            style: TextStyle(fontSize: 12.sp, color: Colors.grey),
                          ),
                        ],
                      ],
                    ),
                  ],
                ),
              ),
              // 心情状态
              if (member.mood != null)
                Container(
                  padding: EdgeInsets.all(8.w),
                  decoration: BoxDecoration(
                    color: member.mood!.color.withOpacity(0.1),
                    shape: BoxShape.circle,
                  ),
                  child: Icon(
                    member.mood!.icon,
                    color: member.mood!.color,
                    size: 20.sp,
                  ),
                ),
              // 编辑按钮
              if (onEdit != null) ...[  
                SizedBox(width: 8.w),
                IconButton(
                  icon: const Icon(Icons.edit),
                  onPressed: onEdit,
                  iconSize: 20.sp,
                  splashRadius: 20.r,
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}
